package es.ats.codington.festival.utils;

import java.io.FileNotFoundException;
import java.io.FileReader; 
import java.io.IOException;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class FERSJsonReader {
	private String path;

	public FERSJsonReader(String path) {
		super();
		this.path = path;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public String readString(String str){
		JSONParser parser = new JSONParser();
		Object obj;
		String s= new String();
		try {
			obj = parser.parse(new FileReader(path));
			JSONObject jsonObject = (JSONObject) obj;
			s = (String) jsonObject.get(str);
			return s;
		} // FileNotFoundException IOException ParseException
		catch (Exception e) {
			e.printStackTrace();
			return s;
		}
	}
	
	public String readStringFromStructure(String structure, String str){
		JSONParser parser = new JSONParser();
		Object obj;
		String s= new String();
		try {
			obj = parser.parse(new FileReader(path));
			JSONObject jsonObject = (JSONObject) obj;
			JSONObject struct = (JSONObject) jsonObject.get(structure);
			s = (String) struct.get(str);
			return s;
		} // FileNotFoundException IOException ParseException
		catch (Exception e) {
			e.printStackTrace();
			return s;
		}
	}

}
